<template>
  <section>
    <ul>
      <li v-for="(item, index) in items" :key="index">{{item.message}}</li>
    </ul>
    <button v-on:click="push">添加数据</button>
    <button v-on:click="pop">删除数据</button>
    <button v-on:click="filter">替换</button>
    <button v-on:click="set(0, {message:'Foo'})">Vue.set设置</button>
    <button v-on:click="splice(0, {message:'Foo'})">splice设置</button>
  </section>
</template>

<script>
import Vue from "vue";

export default {
  name: "ArrayUpdateCheck",
  data() {
    return {
      items: [{ message: "Bar" }, { message: "Foo" }]
    };
  },
  methods: {
    push() {
      this.items.push({ message: "Wee" });
    },
    pop() {
      this.items.pop();
    },
    filter() {
      this.items = this.items.filter(item => item.message.match(/Foo/));
    },
    set(indexOfItem, newValue) {
      Vue.set(this.items, indexOfItem, newValue);
    },
    splice(indexOfItem, newValue) {
      this.items.splice(indexOfItem, 1, newValue);
    }
  }
};
</script>